<?php

namespace App\Controller\App;

use App\Base\BaseController4Restful;
use App\Repository\Banner\BannersRepository;
use App\Repository\Banner\IconsRepository;
use App\Repository\ConfigRepository;
use App\Repository\Shop\ShopCategoryRepository;
use Symfony\Component\Routing\Annotation\Route;

class AppConfigController extends BaseController4Restful
{
    /**
     * @Route("/app/config", name="AppConfig",methods={"GET","POST"})
     */
    public function apiGetUsers(
        ShopCategoryRepository $shopCategoryRepository,
        BannersRepository $bannersRepository,
        IconsRepository $iconsRepository,ConfigRepository $configRepository
    )
    {
        $data = [];
        //商品分类树
        $this->setGroups("cat","banner","app");
        $data["fenlei"] = $shopCategoryRepository->getAllComCategory();
        //首页banner
        $data["banner_dingzhi"] = $bannersRepository->getByPositionId(2);
        $data["banner_feidingzhi"] = $bannersRepository->getByPositionId(1);
        //首页banner
        $data["icon_dingzhi"] = $iconsRepository->getByPositionId(2);
        $data["icon_feidingzhi"] = $iconsRepository->getByPositionId(1);
        //获取配置项
        $allConfig = $configRepository->findAll();
        $data["config"] = [];
        foreach ($allConfig as $row) {
            $data["config"][$row->getK()] = $row;
        }
        return $this->json_out(1,"OK",$data);
    }
}
